﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PaymentHelper.Core.Extension;
using PaymentHelper.Core.ExceptionHandler;

namespace PaymentHelper.Core.RelatedObject
{
    public abstract class PaymentHelperModel
    {
        public virtual dynamic GetValueConfig(string nameSetting,IList<PHSettingItem> listAtrr)
        {
            if (string.IsNullOrEmpty(nameSetting))
                throw new PaymentHelperException(ExceptionLevel.Warning, "PaymentHelperModel-GetValueConfig", "Name of setting is null. Loading specified setting failed !");

            var attr = listAtrr.SingleOrDefault(at => at.Name.Equals(nameSetting, StringComparison.InvariantCultureIgnoreCase));
            if (attr == null)
            {
                string message = string.Format("The attribute that its name is '{0}' doesn't exist or its value is null", nameSetting);
                throw new PaymentHelperException(ExceptionLevel.Warning, "PaymentHelperModel-GetValueConfig", message);
            }

            return attr.Value;
        }

        public abstract void InitModel(IList<PHSettingItem> listAttr);

        public abstract IList<PHSettingItem> ToListAttribute();        
    }
}
